using System;
using System.Reflection;
using System.Collections.Generic;

using DevExpress.ExpressApp;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo.Metadata;
using DevExpress.Xpo;
using System.Configuration;
using XCRM.Module;
using DomainComponents.XCRM;
using DomainComponents.Common;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Utils;

namespace XCRM.Module {
	public sealed partial class XCRMModule : ModuleBase {
		public XCRMModule() {
            TranslatorProvider.RegisterProvider(new GoogleTranslatorProvider());
			InitializeComponent();
		}

        public override void Setup(XafApplication application) {
            base.Setup(application);
            QualifyLeadParameters.QualifyLeadParametersType = typeof(QualifyLeadParametersWithOpportunity);
            QualifyLeadParameters.IContactObjectType = typeof(ICRMContact);
            QualifyLeadParameters.IAccountObjectType = typeof(ICRMAccount);
            QualifyLeadParametersWithOpportunity.IOpportunityObjectType = typeof(ICRMOpportunity);

            if(!XafTypesInfo.IsInitialized) {
                RegisterEntities();
            }
        }

        public override void Setup(ApplicationModulesManager moduleManager) {
            base.Setup(moduleManager);
        }
        public static void RegisterEntities() {
            XafTypesInfo.Instance.AddEntityToGenerate("Opportunity", typeof(ICRMOpportunity));
            XafTypesInfo.Instance.AddEntityToGenerate("Lead", typeof(ICRMLead));
            XafTypesInfo.Instance.AddEntityToGenerate("Order", typeof(ICRMOrder));
            XafTypesInfo.Instance.AddEntityToGenerate("Quote", typeof(ICRMQuote));
            XafTypesInfo.Instance.AddEntityToGenerate("Invoice", typeof(ICRMInvoice));
            XafTypesInfo.Instance.AddEntityToGenerate("Contact", typeof(ICRMContact));
            XafTypesInfo.Instance.AddEntityToGenerate("Account", typeof(ICRMAccount));
            XafTypesInfo.Instance.AddEntityToGenerate("Product", typeof(ICRMProduct));
            XafTypesInfo.Instance.AddEntityToGenerate("SaleItem", typeof(ISaleItem));
            XafTypesInfo.Instance.AddEntityToGenerate("User", typeof(IMyAppUser));
            XafTypesInfo.Instance.AddEntityToGenerate("Role", typeof(IPersistentRole));
            XafTypesInfo.Instance.AddEntityToGenerate("Address", typeof(IGenericAddress));
            //XafTypesInfo.Instance.AddEntityToGenerate("Phone", typeof(IPhone)); TODO
            XafTypesInfo.Instance.AddEntityToGenerate("ObjectAccessPermission", typeof(IObjectAccessPermission));
            XafTypesInfo.Instance.AddEntityToGenerate("Note", typeof(INote));
            XafTypesInfo.Instance.AddEntityToGenerate("PersistentFileData", typeof(IPersistentFileData));
            XafTypesInfo.Instance.AddEntityToGenerate("Event", typeof(ICRMActivity));
            XafTypesInfo.Instance.AddEntityToGenerate("Category", typeof(ICategory));

            XafTypesInfo.Instance.AddEntityToGenerate("LeadToSalesAnalytic", typeof(ILeadHistoryRecord));
        }
	}
}
